package cn.jji8.patternLogin.spigot.login;

import cn.jji8.patternLogin.spigot.data.Data;
import cn.jji8.patternLogin.spigot.PatternLogin;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

import java.util.List;
/**
 * 处理玩家注册的类
 * */
public class PlayerReg extends LoginMode{
    @SuppressWarnings("unused")
    public PlayerReg(Player player) {
        super(player);
        LoginNews.longNews(player,"§a§l请在前方面板输入图像密码完成注册！");
    }
    String password = null;
    /**
     * 玩家连接完成后调用此方法，其他实现类应该重写。
     *
     * @param spotList 密码列表
     */
    @Override
    void complete(List<Choice> spotList) {
        if(password==null){
            password = choiceListToString(spotList);
            LoginNews.longNews(player,"§a§l再输入一次密码");
            return;
        }
        if(password.equals(choiceListToString(spotList))){
            LoginNews.news(player,"§a注册成功！",80);
            Bukkit.getScheduler().runTaskAsynchronously(PatternLogin.getMain(), () -> Data.setPassword(player.getName(),password));
            LoginManager.setLogin(player);
        }else {
            LoginNews.news(player,"§e§l两次密码不同！",81);
            LoginNews.longNews(player,"§a§l请在前方面板输入图像密码完成注册！");
            password = null;
        }
    }
}
